package cn.shuto.liferay.plugin.chart.portlet.admin;

import javax.portlet.ActionRequest;

import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.StringUtil;

public class ChartUtil {
	public static String buildLegendDataJson(ActionRequest request){
		String legendData = "";
		String chart_legend_data_indexes_param = ParamUtil.getString(request, "chart_legend_data_indexes");
		
		String[] chart_legend_data_indexes = StringUtil.split(chart_legend_data_indexes_param, ",");
		if(chart_legend_data_indexes.length>0){
			JSONArray jsonArray = JSONFactoryUtil.createJSONArray();
			for (String chart_legend_data_index : chart_legend_data_indexes) {
				JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
				jsonObject.put("name",  ParamUtil.getString(request, "chart_legend_data_name"+chart_legend_data_index));
				jsonObject.put("icon",  ParamUtil.getString(request, "chart_legend_data_icon"+chart_legend_data_index));
				jsonArray.put(jsonObject);
			}
			legendData=jsonArray.toString();
		}
		return legendData;
	}
}
